<?php

use plugin\coleopenapi\app\api\controller\DispatchController;
use plugin\coleopenapi\app\middleware\RequestIDMiddleware;
use plugin\coleopenapi\app\middleware\RequestLogMiddleware;
use plugin\coleopenapi\app\middleware\StatApiMiddleware;
use plugin\coleopenapi\exception\OpenApiException;
use Webman\Route;
use Wengg\WebmanApiSign\ApiSignMiddleware;


/**
 * 对外api访问
 */
Route::post("/openapi", DispatchController::class . "@dispatch")
    ->middleware(RequestIDMiddleware::class)
    ->middleware(RequestLogMiddleware::class)
    ->middleware(ApiSignMiddleware::class)
    ->middleware(StatApiMiddleware::class);

$forbid = function () {
    return json([
        'code' => OpenApiException::FORBID_ERROR,
        'data' => [],
        "message" => "禁止访问"
    ]);
};
/**
 * 禁止直接访问api模块下的东西
 */
//$forbidPath = [
//    "/app/coleopenapi/api",
//    "/app/coleopenapi/api/",
//    "/app/coleopenapi/api/{controller}",
//    "/app/coleopenapi/api/{controller}/{action}",
//];
//foreach ($forbidPath as $value) {
//    Route::any($value, $forbid);
//}

/**
 * 禁止直接访问api模块下的东西
 */
Route::any('/app/coleopenapi/api/[{path:.+}]', $forbid);
Route::any('/app/coleopenapi/api', $forbid);

